package md.lanjing.com.module_wallet.ui.activity;

import android.os.Bundle;
import android.widget.EditText;


import com.lxh.baselibray.base.BaseResponce;
import com.lxh.baselibray.mvp.MvpActivity;
import com.lxh.baselibray.util.ObjectUtils;
import com.lxh.baselibray.util.RegexUtils;
import com.lxh.baselibray.util.ToastUtils;

import butterknife.BindView;
import butterknife.OnClick;


import com.lxh.baselibray.constant.Constant;

import md.lanjing.com.module_wallet.R;
import md.lanjing.com.module_wallet.R2;
import md.lanjing.com.module_wallet.contact.HashChargeContact;
import retrofit2.Response;

/**
 * 输入hash值充值
 */
public class HashCharegActivity extends MvpActivity<HashChargeContact.HashChargePresent> implements HashChargeContact.IHashChargeView {
    public static final String TYPE = "type";
    @BindView(R2.id.et_hash)
    EditText etHash;
    private String type;

    @Override
    public void initData(Bundle savedInstanceState) {
       type= getIntent().getStringExtra(TYPE);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_hash_charge;
    }


    @OnClick(R2.id.btn_confirm)
    public void onViewClicked() {
        String hashCode=etHash.getText().toString();
        if (ObjectUtils.isEmpty(hashCode)){
            ToastUtils.showLongToast(context,"请输入hash值");
            return;
        }
        if (!RegexUtils.isDigitalAndLetter(hashCode)&&hashCode.length()!=66){
            ToastUtils.showLongToast(context,"请输入66位字母加数字的hash值");
            return;
        }
        showLoadingDialog();
        mPresent.hashCharge(context,hashCode,type);
    }

    @Override
    public void getHashChargeData(Response<BaseResponce> response) {
        dismissLoadingDialog();
        if (response.body().getCode()== Constant.SUCCESS_CODE){
            ToastUtils.showLongToast(context,"充币成功");
            finish();
        }else {
            ToastUtils.showLongToast(context,response.body().getMsg());
        }
    }

    @Override
    protected HashChargeContact.HashChargePresent createPresent() {
        return new HashChargeContact.HashChargePresent();
    }
}
